package com.jic.interaction.ChinaPost.controller;

import com.alibaba.fastjson.JSONObject;
import com.jic.common.base.vo.RestResult;
import com.jic.interaction.ChinaPost.model.entity.UserConsumeDetail;
import com.jic.interaction.ChinaPost.model.vo.request.UserConsumeDetailRequest;
import com.jic.interaction.ChinaPost.model.vo.response.UserConsumeDetailResponse;
import com.jic.interaction.ChinaPost.service.UserConsumeDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

/**
 * @ClassName UserInfoController
 * @Description TODO 用户消费明细
 * @Author 陈鸿锋
 * @Date 2020/11/5 14:29
 * @Version 1.0
 **/
@Api(value="用户消费明细", tags = "用户消费明细", description = "UserConsumeDetailController")
@Slf4j
@RestController
@RequestMapping("/user")
public class UserConsumeDetailController {
    @Autowired
    UserConsumeDetailService userConsumeDetailService;



    @ApiOperation(value = "用户消费明细查询接口", notes = "用户消费明细查询接口")
    @PostMapping("/queryConsumeDetail")
    public RestResult<UserConsumeDetailResponse> getQueryConsumeDetail(@Valid @RequestBody UserConsumeDetailRequest request) throws InterruptedException, ExecutionException, IOException {
        log.info("用户消费明细查询参数入参，{}", JSONObject.toJSONString(request));
        if(request==null){
            return RestResult.error("1292B00000001","无效的请求参数");
        }
        UserConsumeDetail param=new UserConsumeDetail();
        BeanUtils.copyProperties(request,param);
        UserConsumeDetail consumeDetail = userConsumeDetailService.getConsumeDetail(param);
        if(consumeDetail.getBeginTime().getTime()>consumeDetail.getEndTime().getTime()){
        return RestResult.error("1292B00000073","开始时间大于结算时间");
        }
        UserConsumeDetailResponse userConsumeDetailResponse=new UserConsumeDetailResponse();
        BeanUtils.copyProperties(consumeDetail,userConsumeDetailResponse);
        return RestResult.success(userConsumeDetailResponse);

    }

}
